package com.itheima.controller;


import com.itheima.dto.OrderReturnDto;
import com.itheima.pojo.OmsOrderReturnApply;
import com.itheima.service.OmsOrderReturnApplyService;
import com.itheima.vo.PageResultVo;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("returnApply")
public class OmsOrderReturnApplyController {

    @Autowired
    private OmsOrderReturnApplyService omsOrderReturnApplyService;

    /**
     * 修改退货申请状态
     * @param id
     * @param omsOrderReturnApply
     * @return
     */
    @PostMapping("update/status/{id}")
    public Result updateReturn(@PathVariable("id") Integer id, @RequestBody OmsOrderReturnApply omsOrderReturnApply) {
        omsOrderReturnApply.setId(Long.valueOf(id));
        omsOrderReturnApplyService.updateReturn(id, omsOrderReturnApply);
        return Result.success("修改状态成功");
    }


    /**
     * 获取退货申请详情
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result findById(@PathVariable("id") Integer id) {
        OmsOrderReturnApply omsOrderReturnApply = omsOrderReturnApplyService.findById(id);
        return Result.success(omsOrderReturnApply);
    }

    /**
     * 批量删除退货申请
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public Result deletes(@RequestParam ArrayList<Integer> ids) {
        omsOrderReturnApplyService.deletes(ids);
        return Result.success(null);
    }

    /**
     * 查询所有退货订单
     * @param orderReturnDto
     * @return
     */
    @GetMapping("list")
    public Result list(OrderReturnDto orderReturnDto){
       PageResultVo<OmsOrderReturnApply> pageResultVo = omsOrderReturnApplyService.list(orderReturnDto);
        return Result.success(pageResultVo);
    }
}
